﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FileDuplicateUtility
{
    public class Folder
    {
        public Folder(string name, Folder parent = null)
        {
            Parent = parent;
            Name = name;
        }

        public Folder Parent { get; private set; }
        public string Name { get; internal set; }

        private List<Folder> SubFolderList { get; set; }
        private List<File> FileList { get; set; }

        public IEnumerable<Folder> SubFolders { get { return SubFolderList == null ? Enumerable.Empty<Folder>() : SubFolderList.AsEnumerable(); } }
        public IEnumerable<File> Files { get { return FileList == null ? Enumerable.Empty<File>() : FileList.AsEnumerable(); } }

        public string FullPath { get { return Parent == null ? Name : System.IO.Path.Combine(Parent.FullPath, Name); } }
        public System.IO.DirectoryInfo DirectoryInfo { get { return new System.IO.DirectoryInfo(FullPath); } }

        private void RequireSubFolderList()
        {
            if (SubFolderList == null)
            {
                SubFolderList = new List<Folder>();
            }
        }

        private void RequireFileList()
        {
            if (FileList == null)
            {
                FileList = new List<File>();
            }
        }

        public void AddFolder(Folder folder)
        {
            RequireSubFolderList();

            SubFolderList.Add(folder);
        }

        public void AddFolders(IEnumerable<Folder> folders)
        {
            RequireSubFolderList();

            SubFolderList.AddRange(folders);
        }

        public void AddFile(File file)
        {
            RequireFileList();

            FileList.Add(file);
        }

        public void AddFiles(IEnumerable<File> files)
        {
            RequireFileList();

            FileList.AddRange(files);
        }
    }
}
